home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / ImageDraw.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  6.5 KB  |  242 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import Image
  5. import ImageColor
  6.  
  7. try:
  8.     import warnings
  9. except ImportError:
  10.     warnings = None
  11.  
  12.  
  13. class ImageDraw:
  14.     
  15.     def __init__(self, im, mode = None):
  16.         im.load()
  17.         if im.readonly:
  18.             im._copy()
  19.         
  20.         blend = 0
  21.         if mode is None:
  22.             mode = im.mode
  23.         
  24.         if mode != im.mode:
  25.             if mode == 'RGBA' and im.mode == 'RGB':
  26.                 blend = 1
  27.             else:
  28.                 raise ValueError('mode mismatch')
  29.         
  30.         if mode == 'P':
  31.             self.palette = im.palette
  32.         else:
  33.             self.palette = None
  34.         self.im = im.im
  35.         self.draw = Image.core.draw(self.im, blend)
  36.         self.mode = mode
  37.         if mode in ('I', 'F'):
  38.             self.ink = self.draw.draw_ink(1, mode)
  39.         else:
  40.             self.ink = self.draw.draw_ink(-1, mode)
  41.         if mode in ('1', 'P', 'I', 'F'):
  42.             self.fontmode = '1'
  43.         else:
  44.             self.fontmode = 'L'
  45.         self.fill = 0
  46.         self.font = None
  47.  
  48.     
  49.     def setink(self, ink):
  50.         if warnings:
  51.             warnings.warn("'setink' is deprecated; use keyword arguments instead", DeprecationWarning)
  52.         
  53.         if Image.isStringType(ink):
  54.             ink = ImageColor.getcolor(ink, self.mode)
  55.         
  56.         if self.palette and not Image.isNumberType(ink):
  57.             ink = self.palette.getcolor(ink)
  58.         
  59.         self.ink = self.draw.draw_ink(ink, self.mode)
  60.  
  61.     
  62.     def setfill(self, onoff):
  63.         if warnings:
  64.             warnings.warn("'setfill' is deprecated; use keyword arguments instead", DeprecationWarning)
  65.         
  66.         self.fill = onoff
  67.  
  68.     
  69.     def setfont(self, font):
  70.         self.font = font
  71.  
  72.     
  73.     def getfont(self):
  74.         if not self.font:
  75.             import ImageFont
  76.             self.font = ImageFont.load_default()
  77.         
  78.         return self.font
  79.  
  80.     
  81.     def _getink(self, ink, fill = None):
  82.         if ink is None and fill is None:
  83.             if self.fill:
  84.                 fill = self.ink
  85.             else:
  86.                 ink = self.ink
  87.         elif ink is not None:
  88.             if Image.isStringType(ink):
  89.                 ink = ImageColor.getcolor(ink, self.mode)
  90.             
  91.             if self.palette and not Image.isNumberType(ink):
  92.                 ink = self.palette.getcolor(ink)
  93.             
  94.             ink = self.draw.draw_ink(ink, self.mode)
  95.         
  96.         if fill is not None:
  97.             if Image.isStringType(fill):
  98.                 fill = ImageColor.getcolor(fill, self.mode)
  99.             
  100.             if self.palette and not Image.isNumberType(fill):
  101.                 fill = self.palette.getcolor(fill)
  102.             
  103.             fill = self.draw.draw_ink(fill, self.mode)
  104.         
  105.         return (ink, fill)
  106.  
  107.     
  108.     def arc(self, xy, start, end, fill = None):
  109.         (ink, fill) = self._getink(fill)
  110.         if ink is not None:
  111.             self.draw.draw_arc(xy, start, end, ink)
  112.         
  113.  
  114.     
  115.     def bitmap(self, xy, bitmap, fill = None):
  116.         bitmap.load()
  117.         (ink, fill) = self._getink(fill)
  118.         if ink is None:
  119.             ink = fill
  120.         
  121.         if ink is not None:
  122.             self.draw.draw_bitmap(xy, bitmap.im, ink)
  123.         
  124.  
  125.     
  126.     def chord(self, xy, start, end, fill = None, outline = None):
  127.         (ink, fill) = self._getink(outline, fill)
  128.         if fill is not None:
  129.             self.draw.draw_chord(xy, start, end, fill, 1)
  130.         
  131.         if ink is not None:
  132.             self.draw.draw_chord(xy, start, end, ink, 0)
  133.         
  134.  
  135.     
  136.     def ellipse(self, xy, fill = None, outline = None):
  137.         (ink, fill) = self._getink(outline, fill)
  138.         if fill is not None:
  139.             self.draw.draw_ellipse(xy, fill, 1)
  140.         
  141.         if ink is not None:
  142.             self.draw.draw_ellipse(xy, ink, 0)
  143.         
  144.  
  145.     
  146.     def line(self, xy, fill = None, width = 0):
  147.         (ink, fill) = self._getink(fill)
  148.         if ink is not None:
  149.             self.draw.draw_lines(xy, ink, width)
  150.         
  151.  
  152.     
  153.     def shape(self, shape, fill = None, outline = None):
  154.         shape.close()
  155.         (ink, fill) = self._getink(outline, fill)
  156.         if fill is not None:
  157.             self.draw.draw_outline(shape, fill, 1)
  158.         
  159.         if ink is not None:
  160.             self.draw.draw_outline(shape, ink, 0)
  161.         
  162.  
  163.     
  164.     def pieslice(self, xy, start, end, fill = None, outline = None):
  165.         (ink, fill) = self._getink(outline, fill)
  166.         if fill is not None:
  167.             self.draw.draw_pieslice(xy, start, end, fill, 1)
  168.         
  169.         if ink is not None:
  170.             self.draw.draw_pieslice(xy, start, end, ink, 0)
  171.         
  172.  
  173.     
  174.     def point(self, xy, fill = None):
  175.         (ink, fill) = self._getink(fill)
  176.         if ink is not None:
  177.             self.draw.draw_points(xy, ink)
  178.         
  179.  
  180.     
  181.     def polygon(self, xy, fill = None, outline = None):
  182.         (ink, fill) = self._getink(outline, fill)
  183.         if fill is not None:
  184.             self.draw.draw_polygon(xy, fill, 1)
  185.         
  186.         if ink is not None:
  187.             self.draw.draw_polygon(xy, ink, 0)
  188.         
  189.  
  190.     
  191.     def rectangle(self, xy, fill = None, outline = None):
  192.         (ink, fill) = self._getink(outline, fill)
  193.         if fill is not None:
  194.             self.draw.draw_rectangle(xy, fill, 1)
  195.         
  196.         if ink is not None:
  197.             self.draw.draw_rectangle(xy, ink, 0)
  198.         
  199.  
  200.     
  201.     def text(self, xy, text, fill = None, font = None, anchor = None):
  202.         (ink, fill) = self._getink(fill)
  203.         if font is None:
  204.             font = self.getfont()
  205.         
  206.         if ink is None:
  207.             ink = fill
  208.         
  209.         if ink is not None:
  210.             
  211.             try:
  212.                 mask = font.getmask(text, self.fontmode)
  213.             except TypeError:
  214.                 mask = font.getmask(text)
  215.  
  216.             self.draw.draw_bitmap(xy, mask, ink)
  217.         
  218.  
  219.     
  220.     def textsize(self, text, font = None):
  221.         if font is None:
  222.             font = self.getfont()
  223.         
  224.         return font.getsize(text)
  225.  
  226.  
  227.  
  228. def Draw(im, mode = None):
  229.     
  230.     try:
  231.         return im.getdraw(mode)
  232.     except AttributeError:
  233.         return ImageDraw(im, mode)
  234.  
  235.  
  236.  
  237. try:
  238.     Outline = Image.core.outline
  239. except:
  240.     Outline = None
  241.  
  242.